package com.dd.cloud.user.service.mechan.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.user.entity.mechan.MechanReviewLog;
import com.dd.cloud.common.interceptor.UserInterceptor;
import com.dd.cloud.user.mapper.mechan.MechanReviewLogMapper;
import com.dd.cloud.user.req.mechan.MechanInfoReviewReq;
import com.dd.cloud.user.res.mechan.MechanRankApplyDetailRes;
import com.dd.cloud.user.res.mechan.MechanReviewLogRes;
import com.dd.cloud.user.service.mechan.IMechanReviewLogService;
import com.dd.cloud.common.vo.LoginInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author Lx
 * @version 1.0
 */
@Slf4j
@Service
public class MechanReviewLogServiceImpl extends ServiceImpl<MechanReviewLogMapper, MechanReviewLog> implements IMechanReviewLogService {
    /**
     * 创建机构审核记录
     *
     * @param req
     */
    @Override
    public void createMechanReviewLog(MechanInfoReviewReq req) {
        LoginInfo loginInfo = UserInterceptor.getLoginUserInfo(LoginInfo.UserType.ADMIN).get();
        MechanReviewLog mechanReviewLog = new MechanReviewLog();
        mechanReviewLog.setMechanId(req.getMechanId());
        mechanReviewLog.setApplyId(req.getApplyId());
        mechanReviewLog.setStatus(req.getStatus());
        mechanReviewLog.setMsg(req.getMsg());
        mechanReviewLog.setCreateId(loginInfo.getId());
        mechanReviewLog.setCreateDate(LocalDateTime.now());
        save(mechanReviewLog);
    }

    /**
     * 查询机构申请记录的最后一条审核记录
     *
     * @param applyId
     * @return
     */
    @Override
    public MechanReviewLogRes queryMechanReviewLogLast(Integer applyId) {
        MechanReviewLogRes res = getBaseMapper().queryMechanReviewLogLast(applyId);
//        if (res != null) {
//            res.setDepList(JSON.parseArray(res.getDepDiseaseJson(), MechanDepartmentSetReq.class));
//        }
        return res;
    }

    @Override
    public MechanRankApplyDetailRes queryMechanReviewDetail(Integer applyId) {
        MechanRankApplyDetailRes res = getBaseMapper().queryMechanReviewDetail(applyId);
        return res;
    }
}
